import fg from "fast-glob";
import fs from "fs-extra";
import path from "path";
import { toolchain } from "../toolchain.js";

export class ImageReadable {
    public async fixAll(): Promise<void> {
        const imgRoot = path.join(toolchain.opts.projectRoot, 'Assets');
        const imgs = await fg(['**/*.png', '**/*.jpg', '**/*.tga'], { cwd: imgRoot, ignore: ['Spine Examples/**/*.*'] });
        for (const img of imgs) {
            const metaFile = path.join(imgRoot, img) + '.meta';
            const metaContent = await fs.readFile(metaFile, 'utf-8');
            if (metaContent.includes('isReadable: 1')) {
                await fs.writeFile(metaFile, metaContent.replace('isReadable: 1', 'isReadable: 0'), 'utf-8');
            }
        }
    }
}